<template>
  <div class="mod-config">
    <el-form size="small" :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-button v-if="isAuth('user:member:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        align="center"
        type="index"
        header-align="center"
        width="80"
        label="ID" >
      </el-table-column>
      <el-table-column
        prop="realname"
        header-align="center"
        align="center"
        label="真实姓名">
      </el-table-column>
      <el-table-column
        prop="gender"
        header-align="center"
        align="center"
        width="80"
        label="性别">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.gender==1">男</el-tag>
          <el-tag v-else-if="scope.row.gender==2">女</el-tag>
          <el-tag v-else>未知</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="mobile"
        header-align="center"
        align="center"
        label="手机号">
      </el-table-column>
      <el-table-column
        prop="deptName"
        header-align="center"
        align="center"
        label="部门">
      </el-table-column>
      <el-table-column
        prop="identityCard"
        header-align="center"
        align="center"
        label="证件号">
      </el-table-column>
      <!--      <el-table-column-->
      <!--        prop="remark"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--        label="备注">-->
      <!--      </el-table-column>-->
      <el-table-column
        prop="birthdayStr"
        header-align="center"
        align="center"
        label="出生日期">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="recoveryHandle(scope.row.userId,scope.row.realname)">恢复</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.userId,scope.row.realname)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
<!--    <el-pagination-->
<!--      @size-change="sizeChangeHandle"-->
<!--      @current-change="currentChangeHandle"-->
<!--      :current-page="pageIndex"-->
<!--      :page-sizes="[10, 20, 50, 100]"-->
<!--      :page-size="pageSize"-->
<!--      :total="totalPage"-->
<!--      layout="total, sizes, prev, pager, next, jumper">-->
<!--    </el-pagination>-->
    <!-- 弹窗, 新增 / 修改 /查看/工作经历 -->

  </div>
</template>

<script>
  export default {
    data () {
      return {
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
      }
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: '/user/member/deletedList',
          method: 'post',
          data: {
            'page': this.pageIndex,
            'limit': this.pageSize,
            'keyword': this.dataForm.keyword
          }
        }).then(data => {
          if (data && data.code == 200) {
            this.dataList = data.data.list
            this.totalPage = data.data.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      //恢复
      recoveryHandle(id,realname){
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.userId
        })
        var name = realname ? [realname] : this.dataListSelections.map(item => {
          return item.userId
        })
        this.$confirm(`确定对[${name.join(',')}]进行[${realname ? '恢复' : '批量恢复'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: '/user/member/recover',
            method: 'post',
            data: {ids: ids}
          }).then(data => {
            if (data && data.code === 200) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500
              })
              this.getDataList()
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      // 删除
      deleteHandle (id,realname) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.userId
        })
        var name = realname ? [realname] : this.dataListSelections.map(item => {
          return item.userId
        })
        this.$confirm(`确定对[${name.join(',')}]进行[${realname ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: '/user/member/deleteForever',
            method: 'post',
            data: {ids: ids}
          }).then(data => {
            if (data && data.code === 200) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500
              })
              this.getDataList()
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
    }
  }
</script>
